﻿using System;
using SharpKit.JavaScript;

namespace SharpKit.Onx
{
    /// <summary>
    /// Messaging component provides methods for sending SMS and email messages. It also emits events when a new SMS arrives.
    /// https://www.onx.ms/#apiPage/messaging
    /// </summary>
    [JsType(Mode = JsMode.Prototype, Export = false)]
    public class Messaging : Emitter
    {
        //No way to new this up
        private Messaging()
        { }

        #region Actions (Methods)
        /// <summary>
        /// Send a mail using the device mail client.
        /// </summary>
        /// <param name="args">The arguments for sending the mail</param>
        /// <param name="callback">The callback function that is called when the action completed with or without an error.
        ///     Callback signature: function(err); // err contains the error message in case error has occurred or undefined otherwise.</param>
        public void SendMail(SendMailArgs args, Action<string> callback)
        { }

        /// <summary>
        /// Send sms.
        /// </summary>
        /// <param name="args">The arguments for sending the sms</param>
        /// <param name="callback">The callback function that is called when the action completed with or without an error
        /// Callback signature: function(err); // err contains the error message in case error has occurred or undefined otherwise.</param>
        public void SendSms(SendSmsArgs args, Action<string> callback)
        { }
        #endregion

        #region Triggers (Events)
        /// <summary>
        /// trigger is received when an incoming SMS message is detected. Additional trigger data is available in the SmsReceivedSignal parameter passed to the callback function.
        /// </summary>
        public event Action<SmsReceivedSignal> SmsReceived
        {
            [JsMethod(Name = "on", InsertArg0 = "'smsReceived'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'smsReceived'")]
            remove
            {
            }
        }
        #endregion
    }

    /// <summary>
    /// The arguments for sending the mail
    /// </summary>
    [JsType(Mode = JsMode.Json, Export = false)]
    public class SendMailArgs
    {
        /// <summary>
        /// 
        /// </summary>
        [JsProperty(Name = "to", NativeField = true)]
        public string To { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [JsProperty(Name = "subject", NativeField = true)]
        public string Subject { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [JsProperty(Name = "body", NativeField = true)]
        public string Body { get; set; }
    }

    /// <summary>
    /// The arguments for sending the sms
    /// </summary>
    [JsType(Mode = JsMode.Json, Export = false)]
    public class SendSmsArgs
    {
        /// <summary>
        /// String, recipient's phone number
        /// </summary>
        [JsProperty(Name = "to", NativeField = true)]
        public string To { get; set; }

        /// <summary>
        /// String, text body of the message
        /// </summary>
        [JsProperty(Name = "body", NativeField = true)]
        public string Body { get; set; }
    }

    /// <summary>
    /// SmsReceivedSignal will be triggered when a SMS is received.
    /// </summary>
    [JsType(Mode = JsMode.Json, Export = false)]
    public class SmsReceivedSignal : ScriptSignal
    {
        /// <summary>
        /// Retrieves the content of the SMS associated with this signal
        /// </summary>
        [JsProperty(Name = "body", NativeField = true)]
        public string body { get { return null; } }

        /// <summary>
        /// Retrieves the sender's phone number on an SMS associated with this signal
        /// </summary>
        [JsProperty(Name = "from", NativeField = true)]
        public string from { get { return null; } }
    }
}
